//
//  YJDZFffView.m
//  sigleAPP
//
//  Created by SKL on 2017/11/17.
//  Copyright © 2017年 SKL. All rights reserved.
//
#define H 40
#import "YJDzfshitu.h"
#import "YJDOrderLBL.h"
#import "YJDSegBtn.h"
#import "YJDProduct.h"
@interface YJDzfshitu ()
@property (nonatomic, strong) YJDLabel *orderInfoLBL;
@property (nonatomic, strong) YJDCustomButton *enterBtn;
@property (nonatomic, strong) YJDLabel *zffsLBL;
//@property (nonatomic, strong) YJDOrderLBL *themeLBL;
@property (nonatomic, strong) YJDOrderLBL *gameLBL;
@property (nonatomic, strong) YJDOrderLBL *moneyLBL;
@property (nonatomic, strong) UIView *line;
@end
@implementation YJDzfshitu
- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.imageView.hidden = NO;
        self.layer.cornerRadius = 5.0;
        self.layer.masksToBounds = YES;
        self.orderInfoLBL.hidden = self.line.hidden = self.enterBtn.hidden = NO;
        self.gameLBL.hidden = self.moneyLBL.hidden = NO;
        self.zffsLBL.hidden = NO;
        self.backgroundColor = ([YJDHelper shareHelp].style == YJDPlatformStyleImage)?[UIColor clearColor]:[UIColor whiteColor];
    }
    return self;
}
- (YJDImageView *)imageView
{
    if (!_imageView)
    {
        _imageView = [[YJDImageView alloc] init];
        [self addSubview:_imageView];
        [_imageView mas_makeConstraints:^(SK_MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsZero);
        }];
    }
    return _imageView;
}

- (YJDLabel *)orderInfoLBL
{
    if (!_orderInfoLBL)
    {
        _orderInfoLBL = [[YJDLabel alloc]initWithText:@"订单信息"];
        _orderInfoLBL.font = [UIFont systemFontOfSize:19 weight:UIFontWeightBold];
        _orderInfoLBL.textColor = TEXT_BLACK_COLOR;
        [_orderInfoLBL sizeToFit];
        [self addSubview:_orderInfoLBL];
        [_orderInfoLBL mas_updateConstraints:^(SK_MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(10);
            make.top.equalTo(self).with.offset(10);
            make.size.mas_equalTo(_orderInfoLBL.bounds.size);
        }];
    }
    return _orderInfoLBL;
}

- (YJDButton *)cancelBtn
{
    if (!_cancelBtn)
    {
        _cancelBtn = [[YJDButton alloc] init];
        _cancelBtn.style = YJDButtonTitleStyleCameo;
        _cancelBtn.height = ([YJDHelper shareHelp].style == YJDPlatformStyleImage)?TITLE_HEIGHT:TITLE_HEIGHT * 1.5;
        [_cancelBtn setValue:[UIFont systemFontOfSize:15.0 weight:UIFontWeightLight] forKeyPath:@"_titleLBL.font"];
        [_cancelBtn addTarget:self action:@selector(yjd_aciontForCancelBtn) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_cancelBtn];
        [_cancelBtn mas_makeConstraints:^(SK_MASConstraintMaker *make) {
            if ([YJDHelper shareHelp].style == YJDPlatformStyleDefault)
                make.right.equalTo(self).with.offset(0);
            else
                make.right.equalTo(self);
            make.centerY.equalTo(self.orderInfoLBL);
        }];
    }
    return _cancelBtn;
}

- (UIView *)line
{
    if (!_line)
    {
        _line = [[UIView alloc]init];
        _line.backgroundColor = RGBA(223, 223, 223, 1.0);
        [self addSubview:_line];
        [_line mas_makeConstraints:^(SK_MASConstraintMaker *make) {
            make.top.equalTo(self.orderInfoLBL.mas_bottom).with.offset(GAP);
            make.left.equalTo(self).with.offset(GAP);
            make.right.equalTo(self).with.offset(-GAP);
            make.height.mas_equalTo(1);
        }];
    }
    return _line;
}


- (YJDCustomButton *)enterBtn
{
    if (!_enterBtn)
    {
        _enterBtn = [[YJDCustomButton alloc]init];
        [_enterBtn setTitle:@"购买" forState:UIControlStateNormal];
        [_enterBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_enterBtn setTitleColor:TEXT_GRAY_COLOR forState:UIControlStateHighlighted];
        [_enterBtn setBackgroundColor:[YJDHelper shareHelp].color ];
        _enterBtn.showLayerBorder = YES;
        [_enterBtn addTarget:self action:@selector(yjd_actionForEnterBtn) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_enterBtn];
        [_enterBtn mas_makeConstraints:^(SK_MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(100);
            make.right.equalTo(self).with.offset(-100);
            make.bottom.equalTo(self).with.offset(- 8);
            make.height.mas_equalTo(40);
        }];
    }
    return _enterBtn;
}

- (YJDLabel *)zffsLBL
{
    if (!_zffsLBL)
    {
        _zffsLBL = [[YJDLabel alloc]initWithText:@"选择方式"];
        _zffsLBL.textColor = RGBA(109, 109, 109, 1.0);
        _zffsLBL.font = [UIFont systemFontOfSize:17 weight:UIFontWeightBold];
        [self addSubview:_zffsLBL];
        [_zffsLBL mas_updateConstraints:^(SK_MASConstraintMaker *make) {
            make.top.equalTo(_moneyLBL.mas_bottom).with.offset(GAP);
            make.left.equalTo(self).with.offset(GAP);
            make.size.mas_equalTo(_zffsLBL.bounds.size);
        }];
    }
    return _zffsLBL;
}

- (YJDOrderLBL *)gameLBL
{
    if (!_gameLBL)
    {
        _gameLBL = [[YJDOrderLBL alloc]initWithTitle:@"商品信息"];
        [self addSubview:_gameLBL];
        [_gameLBL mas_makeConstraints:^(SK_MASConstraintMaker *make) {
            make.top.equalTo(self.line.mas_bottom);
            make.left.equalTo(self).with.offset(GAP);
            make.right.equalTo(self).with.offset(-GAP);
            make.height.mas_equalTo(H);
        }];
    }
    return _gameLBL;
}

- (YJDOrderLBL *)moneyLBL
{
    if (!_moneyLBL)
    {
        _moneyLBL = [[YJDOrderLBL alloc]initWithTitle:@"商品金额"];
        [self addSubview:_moneyLBL];
        [_moneyLBL mas_makeConstraints:^(SK_MASConstraintMaker *make) {
            make.top.equalTo(self.gameLBL.mas_bottom);
            make.left.equalTo(self).with.offset(GAP);
            make.right.equalTo(self).with.offset(-GAP);
            make.height.mas_equalTo(H);
        }];
    }
    return _moneyLBL;
}

- (void)yjd_zhanshi:(NSString *)xiabiao mz:(NSString *)mz tp:(NSString *)tp;
{
    NSArray *arr1 = [xiabiao componentsSeparatedByString:@","];
    NSArray *arr2 = [mz componentsSeparatedByString:@","];
    NSArray *arr3 = [tp componentsSeparatedByString:@","];
    
    if (arr1.count < 1)
        return;
    
    for (int i = 0; i < arr1.count; i ++) {
        int num = [arr1[i] intValue];
        NSString *zfmz = arr2[i];
        NSString *zftp = arr3[i];
        YJDSegBtn *segBtn = [[YJDSegBtn alloc]initWithTitle:zfmz icon:zftp];
        segBtn.tag = 200 + num;
        [segBtn addTarget:self action:@selector(yjd_SegBtnMethod:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:segBtn];
        [segBtn mas_makeConstraints:^(SK_MASConstraintMaker *make) {
            make.top.equalTo(_moneyLBL.mas_bottom).with.offset(H * i);
            make.left.equalTo(_zffsLBL.mas_right).with.offset(GAP);
            make.right.equalTo(self).with.offset(-GAP);
            make.height.mas_equalTo(H);
        }];
    }
}

- (void)yjd_productInfo:(YJDProduct *)product
{
    if (product)
    {
        self.gameLBL.content = product.goodsTitle;
        self.moneyLBL.content = [NSString stringWithFormat:@"¥%@",product.goodsPrice];
    }
}

- (void)yjd_aciontForCancelBtn
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(yjd_actionWithSubViewEvent:)])
    {
        [self.delegate yjd_actionWithSubViewEvent:YJDzfshituEventBack];
    }
}

- (void)yjd_closeEnterBtn
{
    self.enterBtn.userInteractionEnabled = NO;
    [self.enterBtn setBackgroundColor:TEXT_GRAY_COLOR];
}

- (void)yjd_openEnterBtn
{
    self.enterBtn.userInteractionEnabled = YES;
    [self.enterBtn setBackgroundColor:[YJDHelper shareHelp].color];

}

- (void)yjd_actionForEnterBtn
{
    BOOL selected = NO;
    for (UIView *view in [self subviews]) {
        if (view.tag > 200)
        {
            YJDSegBtn * button = (YJDSegBtn *)view;
            if (button.selected && self.delegate  && [self.delegate respondsToSelector:@selector(yjd_actionForSelectWay:)])
            {
                selected = YES;
                [self.delegate yjd_actionForSelectWay:(int)button.tag - 200];
                return;
            }
        }
    }
    if (!selected)
    {
        [YJDAlert yjd_showMessage:@"先选择一种方式" hidden:nil];
    }
}

- (void)yjd_SegBtnMethod:(YJDSegBtn *)sender
{
    sender.selected = YES;
    for (UIView *view in [self subviews])
    {
        if (view.tag > 200 && view.tag != sender.tag)
        {
            YJDSegBtn * button = (YJDSegBtn *)view;
            button.selected = NO;
        }
    }
}


/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
